package cn.iocoder.yudao.module.social.api.container;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.social.api.container.dto.ContainerReqDTO;
import cn.iocoder.yudao.module.social.api.container.dto.ContainerRespDTO;
import cn.iocoder.yudao.module.social.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;

/**
 * RPC 服务 - 容器管理
 *
 * @author 芋道源码
 */
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿：fallbackFactory =
@Tag(name = "RPC 服务 - 容器管理")
public interface ContainerApi {

    String PREFIX = ApiConstants.PREFIX + "/container";

    @PostMapping(PREFIX + "/create")
    @Operation(summary = "创建容器")
    CommonResult<Long> createContainer(@RequestBody ContainerReqDTO reqDTO);

    @PutMapping(PREFIX + "/update")
    @Operation(summary = "更新容器")
    CommonResult<Boolean> updateContainer(@RequestBody ContainerReqDTO reqDTO);

    @DeleteMapping(PREFIX + "/delete")
    @Operation(summary = "删除容器")
    @Parameter(name = "id", description = "容器编号", example = "1024", required = true)
    CommonResult<Boolean> deleteContainer(@RequestParam("id") Long id);

    @GetMapping(PREFIX + "/get")
    @Operation(summary = "通过容器 ID 查询容器")
    @Parameter(name = "id", description = "容器编号", example = "1024", required = true)
    CommonResult<ContainerRespDTO> getContainer(@RequestParam("id") Long id);

    @GetMapping(PREFIX + "/list")
    @Operation(summary = "批量查询容器信息")
    @Parameter(name = "ids", description = "容器编号数组", example = "1,2", required = true)
    CommonResult<List<ContainerRespDTO>> getContainerList(@RequestParam("ids") Collection<Long> ids);

    @GetMapping(PREFIX + "/list-by-type")
    @Operation(summary = "根据类型查询容器列表")
    @Parameter(name = "type", description = "容器类型", example = "board", required = true)
    CommonResult<List<ContainerRespDTO>> getContainerListByType(@RequestParam("type") String type);

    @GetMapping(PREFIX + "/list-by-parent")
    @Operation(summary = "根据父容器查询子容器列表")
    @Parameter(name = "parentId", description = "父容器编号", example = "1", required = true)
    CommonResult<List<ContainerRespDTO>> getContainerListByParent(@RequestParam("parentId") Long parentId);

    /**
     * 批量查询容器 MAP
     *
     * @param ids 容器编号列表
     * @return 容器 MAP
     */
    default Map<Long, ContainerRespDTO> getContainerMap(Collection<Long> ids) {
        return convertMap(getContainerList(ids).getCheckedData(), ContainerRespDTO::getId);
    }

}
